package com.xbts.system.domain;


import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import com.xbts.common.annotation.Excel;
import com.xbts.common.utils.StringUtils;
import com.xbts.common.core.domain.BaseEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * 首页产品类型对象 cn_home_product_type
 *
 * @author xbts
 * @date 2023-11-30
 */
@Data
@ApiModel("首页产品类型对象")
@TableName("cn_home_product_type")
public class CnHomeProductType extends BaseEntity {

    private static final long serialVersionUID=1L;

    /** id */
    @TableId
    private String id;

    /** 类型名称 */
    @Excel(name = "类型名称")
    @ApiModelProperty("类型名称")
    @NotEmpty(message = "类型名称不能为空")
    private String typeName;

    /** 排序（数值越小越靠前） */
    @Excel(name = "排序", readConverterExp = "数=值越小越靠前")
    @ApiModelProperty("排序")
    @NotNull(message = "排序不能为空")
    private Integer sort;

    /** 父级ID */
    @ApiModelProperty("父级ID")
    private String parentId;

    /** 是否存在子级 */
    @ApiModelProperty("是否存在子级（1存在， 非1不存在）")
    private String haveChildren;

    /** 状态（1展示，2隐藏） */
    @Excel(name = "状态", readConverterExp = "1=展示，2隐藏")
    @ApiModelProperty("状态")
    @NotEmpty(message = "状态不能为空")
    private String status;

    @TableField(exist = false)
    private List<CnHomeProduct> productList = new ArrayList<>();
    @TableField(exist = false)
    private List<CnHomeProductType> productChildrenTypeList = new ArrayList<>();

    public<T> QueryWrapper<T> queryWrapper(){
        QueryWrapper<T> queryWrapper=new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(typeName),"type_name",typeName);
        queryWrapper.eq(StringUtils.isNotEmpty(status),"status",status);
        queryWrapper.eq(StringUtils.isNotEmpty(parentId),"parent_id",parentId);
        queryWrapper.eq(StringUtils.isNotEmpty(haveChildren),"have_children",haveChildren);
        queryWrapper.orderByAsc("sort");
        queryWrapper.orderByDesc("update_time");
        return queryWrapper;
    }
}